package com.jian.socks5.tcp;

import com.jian.socks5.common.Constants;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.net.InetSocketAddress;

public class TCPBootstrap {

    public static Bootstrap newDefBootstrap(InetSocketAddress inetSocketAddress) {
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(Constants.eventExecutors);
        // 设置读缓冲区为2M
        bootstrap.option(ChannelOption.SO_RCVBUF, 2048 * 1024);
        // 设置写缓冲区为1M
        bootstrap.option(ChannelOption.SO_SNDBUF, 1024 * 1024);
        bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.remoteAddress(inetSocketAddress);
        bootstrap.handler(Constants.server2ClientHandler);
        return bootstrap;
    }
}
